﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Plat.WfProcess.Business;

namespace Plat.WfProcess.Engine
{
    /// <summary>
    /// 工作项执行结果类
    /// </summary>
    public class WorkItemExecutedResult
    {
        /// <summary>
        /// 消息提示
        /// </summary>
        public string Message
        {
            get;
            set;
        }

        /// <summary>
        /// 错误代码
        /// </summary>
        public int ErrorCode
        {
            get;
            set;
        }

        /// <summary>
        /// 执行结果状态
        /// </summary>
        public WorkItemExecutedStatus Status
        {
            get;
            set;
        }
        
        private WorkItemExecutedResult(WorkItemExecutedStatus status,
            string message,
            int errorCode) 
        {
            Status = status;
            Message = message;
            ErrorCode = errorCode; 
        }

        /// <summary>
        /// 创建类
        /// </summary>
        /// <param name="status"></param>
        /// <returns></returns>
        internal static WorkItemExecutedResult CreateWorkItemExecutedResult(WorkItemExecutedStatus status)
        {
            WorkItemExecutedResult result = null;
            switch (status)
            {
                case WorkItemExecutedStatus.NotStarted:
                    result = new WorkItemExecutedResult(WorkItemExecutedStatus.NotStarted,
                        "流程实例工作项的执行尚未启动（可能的原因是未获取到可执行的步骤列表）！",
                        1000);
                    break;
                case WorkItemExecutedStatus.Failed:
                    result = new WorkItemExecutedResult(WorkItemExecutedStatus.Failed,
                        "流程实例的工作项执行失败！",
                        1001);
                    break;
                case WorkItemExecutedStatus.Successed:
                    result = new WorkItemExecutedResult(WorkItemExecutedStatus.Successed,
                        "流程实例的工作项执行成功!",
                        1002);
                    break;
                case WorkItemExecutedStatus.WaitingForOthersJoin:
                    result = new WorkItemExecutedResult(WorkItemExecutedStatus.WaitingForOthersJoin,
                        "流程实例的工作项无法进行下一步的运行，原因：等待其它要合并的节点执行！",
                        1003);
                    break;
                default:
                    break;                  
            }
            return result;
        }
    }
}
